<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";

if(isset($_POST[cmdAddAssign]) && $_POST[cmdAddAssign]!='')
{
	$getDeviceGeofence = "SELECT * FROM tb_assigngeofence WHERE tag_diId = ".$_POST[map_device_id]." AND tag_geofenceId = ".$_POST[selGeofenceId];	
	$resDeviceGeofence = $db->query($getDeviceGeofence);
	if($db->affected_rows == 0 )
	{
		$data['tag_geofenceId'] = $_POST[selGeofenceId];
		$data['tag_alertType'] = "";		
		$data['tag_diId'] = $_POST[map_device_id];
		$data['tag_alertSrc'] = "";
		$data['tag_contactIds'] = $_POST[txtMobiEmail];
		$data['tag_inout'] = $_POST[selInOut];
		$data['tag_noofTimes'] = $_POST[selNoofAlert];
		$data['tag_donotTime'] = $_POST[time3]."#".$_POST[time4];
		$data['tag_clientId'] = $_SESSION[clientID];
		$data['tag_isActive'] = 1;
		
		//print_r($data);
		//exit;
		if($db->query_insert("tb_assigngeofence", $data))
		{
			header("location:?ch=status&au=18&msg=1");
			exit;
		}
		else
		{
			header("location:?ch=status&au=18&msg=0");
			exit;
		}
		
	}
	else
	{
		header("location:?ch=status&au=18&msg=2");
		exit;
	}
}

if(isset($_POST[cmdUpdateAssign]) && $_POST[cmdUpdateAssign]!='')
{
	
	$data['tag_geofenceId'] = $_POST[selGeofenceId];
	$data['tag_alertType'] = "";		
	$data['tag_diId'] = $_POST[map_device_id];
	$data['tag_alertSrc'] = "";
	$data['tag_contactIds'] = $_POST[txtMobiEmail];
	$data['tag_inout'] = $_POST[selInOut];
	$data['tag_noofTimes'] = $_POST[selNoofAlert];
	$data['tag_donotTime'] = $_POST[time3]."#".$_POST[time4];
	$data['tag_clientId'] = $_SESSION[clientID];
	
	//print_r($data);
	//exit;
	if($db->query_update("tb_assigngeofence", $data , "tag_id=".$_POST[txtAssGeoId]))
	{
		header("location:?ch=status&au=19&msg=1");
		exit;
	}
	else
	{
		header("location:?ch=status&au=19&msg=0");
		exit;
	}
}
if(isset($_POST[cmdUpdateAlert]) && $_POST[cmdUpdateAlert]!='')
{
	$data['tdai_deviceId'] = $_POST[map_device_id];
	$data['tdai_clientId'] = $_SESSION[clientID];
	$data['tdai_purpose'] = $_POST[txtPurpose];
	$data['tdai_alertBy'] = $_POST[rdAlertBy];
	
	if($_POST[rdAlertBy] == "Date")
		$data['tdai_alertSrc'] = $_POST[txtAlertDate];
	else if($_POST[rdAlertBy] == "Meter")
		$data['tdai_alertSrc'] = $_POST[txtOdoMRead];
	else if($_POST[rdAlertBy] == "OverSpeed" || $_POST[rdAlertBy] == "Immbolize")
		$data['tdai_alertSrc'] = $_POST[sdMinSpeed]."#".$_POST[sdMaxSpeed];
	else if($_POST[rdAlertBy] == "OverStay")
		$data['tdai_alertSrc'] = $_POST[txtOverStay];
	else if($_POST[rdAlertBy] == "LowBattery")
		$data['tdai_alertSrc'] = $_POST[txtLowBattery];
	else if($_POST[rdAlertBy] == "SOS" || $_POST[rdAlertBy] == "Ignition" || $_POST[rdAlertBy] == "FuelTheft")
		$data['tdai_alertSrc'] = "";
		
	$data['tdai_status'] = 0;
	$data['tdai_alertType'] = "";
	$data['tdai_source'] = "";
	$data['tdai_contactIds'] = $_POST[txtContIds];
	$data['tdai_description'] = $_POST[txtAreaAlertDesc];
	$data['tdai_updateDate'] = date("Y-m-d H:i:s");
	$data['tdai_donotTime'] = $_POST[time3]."#".$_POST[time4];
	
	//print_r($data);
	//exit;
	if($db->query_update("tb_device_alert_info", $data, "tdai_id=".$_POST[txtAlertId]))
		$res = 1;
	else $res = 0;
	
	header("location:?ch=status&au=23&msg=".$res);
	exit;
}
if(isset($_POST[cmdAddAlert]) && $_POST[cmdAddAlert]!='')
{
	$data['tdai_deviceId'] = $_POST[map_device_id];
	$data['tdai_clientId'] = $_SESSION[clientID];
	$data['tdai_purpose'] = $_POST[txtPurpose];
	$data['tdai_alertBy'] = $_POST[rdAlertBy];
	
	if($_POST[rdAlertBy] == "Date")
		$data['tdai_alertSrc'] = $_POST[txtAlertDate];
	else if($_POST[rdAlertBy] == "Meter")
		$data['tdai_alertSrc'] = $_POST[txtOdoMRead];
	else if($_POST[rdAlertBy] == "OverSpeed" || $_POST[rdAlertBy] == "Immbolize")
		$data['tdai_alertSrc'] = $_POST[sdMinSpeed]."#".$_POST[sdMaxSpeed];
	else if($_POST[rdAlertBy] == "OverStay")
		$data['tdai_alertSrc'] = $_POST[txtOverStay];
	else if($_POST[rdAlertBy] == "LowBattery")
		$data['tdai_alertSrc'] = $_POST[txtLowBattery];
	else if($_POST[rdAlertBy] == "SOS" || $_POST[rdAlertBy] == "Ignition" || $_POST[rdAlertBy] == "FuelTheft")
		$data['tdai_alertSrc'] = "";
		
	$data['tdai_status'] = 0;
	$data['tdai_alertType'] = "";
	$data['tdai_source'] = "";
	$data['tdai_contactIds'] = $_POST[txtContIds];
	$data['tdai_description'] = $_POST[txtAreaAlertDesc];
	$data['tdai_donotTime'] = $_POST[time3]."#".$_POST[time4];
	
	//echo "<br><br>";
	//print_r($data);
	//exit;
	
	if($db->query_insert("tb_device_alert_info", $data))
		$res = 1;
	else $res = 0;
	
	header("location:?ch=status&au=22&msg=".$res);
	exit;
}
//	ADD USER INFORMATION
if(isset($_POST[cmdSubmitUpdateInusrance]) && $_POST[cmdSubmitUpdateInusrance]!='')
{
	//print_r($_POST);
	$data['tdii_clientId'] = $_POST[txtClientId];
	$data['tdii_deviceId'] = $_POST[map_device_id];
	$data['tdii_policyNum'] = $_POST[txtPolicyNo];
	$data['tdii_policyCompany'] = $_POST[txtPolicyComp];
	$data['tdii_policyAmount'] = $_POST[txtPolicyAmt];
	$data['tdii_policyExpDate'] = date("Y-m-d",strtotime($_POST[txtPolicyExp]));
	$data['tdii_alertDate'] = date("Y-m-d",strtotime("-".$_POST[txtNoofDay]."days ".$_POST[txtPolicyExp]));
	$data['tdii_policyContPerson'] = $_POST[txtPolicyPerson];
	$data['tdii_policyContMobile'] = $_POST[txtPolicyMobile];
	
	
	//print_r($data);
	//exit;
	if($db->query_update("tb_device_insurance_info", $data , "tdii_id=".$_POST[txtDeviceId]))
		$res = 1;
	else $res = 0;
	
	header("location:?ch=status&au=21&msg=".$res);
	exit;
}
if(isset($_POST[cmdSubmitAddInusrance]) && $_POST[cmdSubmitAddInusrance]!='')
{
	//print_r($_POST);
	$data['tdii_clientId'] = $_POST[txtClientId];
	$data['tdii_deviceId'] = $_POST[map_device_id];
	$data['tdii_policyNum'] = $_POST[txtPolicyNo];
	$data['tdii_policyCompany'] = $_POST[txtPolicyComp];
	$data['tdii_policyAmount'] = $_POST[txtPolicyAmt];
	$data['tdii_policyExpDate'] = date("Y-m-d",strtotime($_POST[txtPolicyExp]));
	$data['tdii_alertDate'] = date("Y-m-d",strtotime("-".$_POST[txtNoofDay]."days ".$_POST[txtPolicyExp]));
	$data['tdii_policyContPerson'] = $_POST[txtPolicyPerson];
	$data['tdii_policyContMobile'] = $_POST[txtPolicyMobile];
	
	
	//print_r($data);
	//exit;
	
	if($db->query_insert("tb_device_insurance_info", $data))
		$res = 1;
	else $res = 0;
	
	header("location:?ch=status&au=20&msg=".$res);
	exit;
}

if(isset($_POST[cmdSubmitAddDevice]) && $_POST[cmdSubmitAddDevice]!='')
{
	$txtDeviceName = str_replace(" ","_",$_POST[txtDeviceName]);

	/*$sql = "SELECT * FROM tb_deviceinfo WHERE di_clientId = ".$_SESSION[clientID]." AND di_deviceId = '".$txtDeviceName."'";
	$rows = $db->query($sql);
	if($db->affected_rows)
	{
		header("location:?ch=status&au=3&msg=0");
		exit;
	}
	else*/ $data['di_deviceId'] = $txtDeviceName;


	/*$sql = "SELECT * FROM tb_deviceinfo WHERE di_clientId = ".$_SESSION[clientID]." AND di_imeiId = '".$_POST[txtImeiNo]."'";
	$rows = $db->query($sql);
	if($db->affected_rows)
	{
		header("location:?ch=status&au=3&msg=0");
		exit;
	}
	else*/ $data['di_imeiId'] = $_POST[txtImeiNo];
	
	/*$sql = "SELECT * FROM tb_deviceinfo WHERE di_clientId = ".$_SESSION[clientID]." AND di_mobileNo = '".$_POST[txtMobileNo]."'";
	$rows = $db->query($sql);
	exit;
	if($db->affected_rows)
	{
		header("location:?ch=status&au=3&msg=0");
		exit;
	}
	else*/ $data['di_mobileNo'] = $_POST[txtMobileNo];

$data['di_odoMeter'] = $_POST[txtOdometer];
$data['di_deviceModel'] = $_POST[txtDeviceModel];
$data['di_userId'] = $_SESSION[userID];
$data['di_clientId'] = $_SESSION[clientID];

 
    if($_POST[txtImmobalize]=='1'){
	      $data['di_immoblize'] ='1';
   } else {
     $data['di_immoblize'] = '0';
   }

	if($_POST[txtNeedfuel]=='1'){
	 $data['di_fuel'] = '1';
	} else {
      $data['di_fuel'] = '0';
	}

    /*Port numbers*/
	$data['di_Fuelport'] = $_POST[txtFuelport];
	$data['di_Acport'] = $_POST[txtAcport];
	$data['di_Ignitionport'] = $_POST[txtIgport];
	$data['di_Sosport'] = $_POST[txtSosport];
	$data['di_Engineport'] = $_POST[txtEngineport];


if(isset($_POST[txtStatus]) && $_POST[txtStatus]!=""){
	$data['di_status'] = $_POST[txtStatus];
}



if($db->query_insert("tb_deviceinfo", $data))
	$res = 1;
else $res = 0;

header("location:?ch=status&au=3&msg=".$res);
exit;

}


//		UPDATE USER INFORMATION
if(isset($_POST[cmdSubmitUpdateDevice]) && $_POST[cmdSubmitUpdateDevice]!='')
{
	$txtDeviceName = str_replace(" ","_",$_POST[txtDeviceName]);

	/*$sql = "SELECT * FROM tb_deviceinfo WHERE di_clientId = ".$_SESSION[clientID]." AND di_deviceId = '".$txtDeviceName."'";
	$rows = $db->query($sql);
	if($db->affected_rows)
	{
		header("location:?ch=status&au=3&msg=0");
		exit;
	}
	else*/ $data['di_deviceId'] = $txtDeviceName;


	/*$sql = "SELECT * FROM tb_deviceinfo WHERE di_clientId = ".$_SESSION[clientID]." AND di_imeiId = '".$_POST[txtImeiNo]."'";
	$rows = $db->query($sql);
	if($db->affected_rows)
	{
		header("location:?ch=status&au=3&msg=0");
		exit;
	}
	else*/ $data['di_imeiId'] = $_POST[txtImeiNo];
	
	/*$sql = "SELECT * FROM tb_deviceinfo WHERE di_clientId = ".$_SESSION[clientID]." AND di_mobileNo = '".$_POST[txtMobileNo]."'";
	$rows = $db->query($sql);
	exit;
	if($db->affected_rows)
	{
		header("location:?ch=status&au=3&msg=0");
		exit;
	}
	else*/ $data['di_mobileNo'] = $_POST[txtMobileNo];
	$data['di_odoMeter'] = $_POST[txtOdometer];
	$data['di_deviceModel'] = $_POST[txtDeviceModel];
	$data['di_updateDate'] = "NOW()";

if(isset($_POST[txtStatus]) && $_POST[txtStatus]!=""){
	$data['di_status'] = $_POST[txtStatus];
}

//print_r($data);
//exit;

if($db->query_update("tb_deviceinfo", $data , "di_id=".$_POST[txtDeviceId]))
	$res = 1;
else $res = 0;

header("location:?ch=status&au=4&msg=".$res);
exit;

}



if(isset($_POST[cmdSubmitClientAddDevice]) && $_POST[cmdSubmitClientAddDevice]!='')
{
	$txtDeviceUnId = str_replace(" ","_",$_POST[txtDeviceUnId]);
	$data['di_deviceId'] = $txtDeviceUnId;

	if(isset($_POST[txtDeviceName]) && $_POST[txtDeviceName]!="")
	{
		$data['di_deviceName'] = $_POST[txtDeviceName];
	}

	$data['di_imeiId'] = $_POST[txtImeiNo];
	$data['di_mobileNo'] = $_POST[txtMobileNo];

	$data['di_odoMeter'] = $_POST[txtOdometer];
	$data['di_deviceModel'] = $_POST[txtDeviceModel];
	$data['di_userId'] = $_POST[txtClientUserId];
	$data['di_clientId'] = $_POST[txtClientId];

 	/* Immobalize */
	if($_POST[txtIsImmobalize] != "")
	{
	  $data['di_immoblize'] = $_POST[txtIsImmobalize];
	}
	else
	{
		$data['di_immoblize'] = 0;
	}
	
	/*analog Port numbers*/
	if($_POST[txtNoofAnalog] > 0)
	{
		$t1 = -1;
		for($j=1;$j<=$_POST[txtNoofAnalog];$j++)
		{
			if($_POST["txtANAInput".$j] !=0 && $_POST["txtANAInput".$j] != $t1 )
			{
				$w = 1;
				
				$t1 = $_POST["txtANAInput".$j];
				
				if($analogData.length == 0)
					$analogData = $_POST["txtANALabelInput".$j]."=".$_POST["txtANAInput".$j]."(";
				else
					$analogData .= $_POST["txtANALabelInput".$j]."=".$_POST["txtANAInput".$j]."(";
					
				
				while(isset($_POST[$j.'txtTankSize'.$w]) && isset($_POST[$j.'txtVoltage'.$w]))
				{
					$analogData .= $_POST[$j.'txtTankSize'.$w]."_".$_POST[$j.'txtVoltage'.$w]."#";
					//$data['di_analogPort'] .= $_POST['txtLabelInput'.$j]."_".$_POST['txtANAInput'.$j]."#";
					$w++;
				}
				$analogData .= ")@";
				$data['di_analogPort'] .= $analogData;
			}
			else if($_POST["txtANAInput".$j] !=0 && $_POST["txtANAInput".$j] == $t1 )
			{
				header("location:?ch=status&au=12&msg=0");
				exit;
			}
			else $data['di_analogPort'] .= "";
		}
	}

	/*input Port numbers*/
	if($_POST[txtNoofInput] > 0)
	{
		$t2 = -1;
		for($j=1;$j<=$_POST[txtNoofInput];$j++)
		{
			if($_POST['txtINInput'.$j] != 0 && $_POST['txtINInput'.$j] != $t2)
			{
				$t2 = $_POST['txtINInput'.$j];
				$data['di_inputPort'] .= $_POST['txtINLabelInput'.$j]."_".$_POST['txtINInput'.$j]."#";
			}
			else if($_POST['txtINInput'.$j] != 0 && $_POST['txtINInput'.$j] == $t2)
			{
				//echo 'b'.$_POST['txtINInput'.$j]." == ".$t2."<br>";
				header("location:?ch=status&au=12&msg=0");
				exit;
			}else $data['di_inputPort'] .= "";
		}
	}
	
	/*output Port numbers*/
	if($_POST[txtNoofOutput] > 0)
	{
		$t3 = -1;
		for($j=1;$j<=$_POST[txtNoofOutput];$j++)
		{
			if($_POST['txtOUTInput'.$j] != 0 && $_POST['txtOUTInput'.$j] != $t3)
			{
				$t3 = $_POST['txtOUTInput'.$j];
				$data['di_outputPort'] .= $_POST['txtOUTLabelInput'.$j]."_".$_POST['txtOUTInput'.$j]."#";
			}
			else if($_POST['txtOUTInput'.$j] != 0 && $_POST['txtOUTInput'.$j] == $t3)
			{
				header("location:?ch=status&au=12&msg=0");
				exit;
			}else $data['di_outputPort'] .= "";
		}
	}
	
    /*device icon*/
	$data['di_mapIcon'] = $_POST[rdDevImg];

	 /* active / deactive*/
	if(isset($_POST[txtStatus]) && $_POST[txtStatus]!="")
	{
		$data['di_status'] = $_POST[txtStatus];
	}
	
	if($_FILES["fileDeviceLogo"]["name"]!='')
	{
		$type = explode("/",$_FILES["fileDeviceLogo"]["type"]);
		$filename = time().".".$type[1];
		if ((($_FILES["fileDeviceLogo"]["type"] == "image/gif")
		|| ($_FILES["fileDeviceLogo"]["type"] == "image/jpeg")
		|| ($_FILES["fileDeviceLogo"]["type"] == "image/pjpeg"))
		&& ($_FILES["fileDeviceLogo"]["size"] < 200000))
		{
			if ($_FILES["fileDeviceLogo"]["error"] > 0)
			{
				echo "Return Code: " . $_FILES["fileDeviceLogo"]["error"] . "<br />";
				//header("location:?ch=status&au=7&msg=1");
				//exit;
			}
			else
			{
				if (file_exists("unit_img/" . $filename))
				{
					echo $_FILES["fileDeviceLogo"]["name"] . " already exists. ";
					//header("location:?ch=status&au=7&msg=0");
					//exit;
				}
				else
				{
					move_uploaded_file($_FILES["fileDeviceLogo"]["tmp_name"],"unit_img/" . $filename);
					$data['di_deviceImg'] = $filename;
				}
			}
		}
	}
	else
	{
		if($_POST[rdDevImg]!=""){$data['di_deviceImg'] = $_POST[rdDevImg];}
	}
	
echo "<br><br>";
print_r($data);
//exit;

if($db->query_insert("tb_deviceinfo", $data))
	$res = 1;
else $res = 0;

header("location:?ch=status&au=12&msg=".$res);
exit;

}


//		UPDATE USER INFORMATION
if(isset($_POST[cmdSubmitClientUpdateDevice]) && $_POST[cmdSubmitClientUpdateDevice]!='')
{
	$data['di_imeiId'] = $_POST[txtImeiNo];
	$data_fuel['imei'] = $_POST[txtImeiNo];
	$txtDeviceUnId = str_replace(" ","_",$_POST[txtDeviceUnId]);
	$data['di_deviceId'] = $txtDeviceUnId;	
	
	
     if(isset($_POST[txtDeviceName]) && $_POST[txtDeviceName]!=""){
	  $data['di_deviceName'] = $_POST[txtDeviceName];
	 }
	 
	$data['di_odoMeter'] = $_POST[txtOdometer];
	$data['di_deviceModel'] = $_POST[txtDeviceModel];
   
	if($_POST[txtIsImmobalize] != "")
	{
	  $data['di_immoblize'] = $_POST[txtIsImmobalize];
	}
	else
	{
		$data['di_immoblize'] = 0;
		/*$query = "select * from tb_device_alert_info where tdai_alertBy = 'Immbolize' AND tdai_deviceId=".$_POST[txtDeviceId];
		$rows = $db->query($query);
		if($db->affected_rows > 0)
		{
			$query1 = "DELETE from tb_device_alert_info where tdai_alertBy = 'Immbolize' AND tdai_deviceId=".$_POST[txtDeviceId];
			$rows1 = $db->query($query1);
		}*/
	}
	
	/*analog Port numbers*/
	if($_POST[txtNoofAnalog] > 0)
	{
		$t1 = -1;
		for($j=1;$j<=$_POST[txtNoofAnalog];$j++)
		{
			if($_POST["txtANAInput".$j] !=0 && $_POST["txtANAInput".$j] != $t1 )
			{
				$w = 1;
				
				$t1 = $_POST["txtANAInput".$j];
				
				if($analogData.length == 0)
					$analogData = $_POST["txtANALabelInput".$j]."=".$_POST["txtANAInput".$j]."(";
				else
					$analogData .= $_POST["txtANALabelInput".$j]."=".$_POST["txtANAInput".$j]."(";
					
				
				while(isset($_POST[$j.'txtTankSize'.$w]) && isset($_POST[$j.'txtVoltage'.$w]))
				{
					$analogData .= $_POST[$j.'txtTankSize'.$w]."_".$_POST[$j.'txtVoltage'.$w]."#";
					//$data['di_analogPort'] .= $_POST['txtLabelInput'.$j]."_".$_POST['txtANAInput'.$j]."#";
					$w++;
				}
				$analogData .= ")@";
				$data['di_analogPort'] .= $analogData;
			}
			else if($_POST["txtANAInput".$j] !=0 && $_POST["txtANAInput".$j] == $t1 )
			{
				header("location:?ch=status&au=12&msg=0");
				exit;
			}
			else $data['di_analogPort'] .= "";
		}
	}

	/*input Port numbers*/
	if($_POST[txtNoofInput] > 0)
	{
		$t2 = -1;
		for($j=1;$j<=$_POST[txtNoofInput];$j++)
		{
			if($_POST['txtINInput'.$j] != 0 && $_POST['txtINInput'.$j] != $t2)
			{
				$t2 = $_POST['txtINInput'.$j];
				$data['di_inputPort'] .= $_POST['txtINLabelInput'.$j]."_".$_POST['txtINInput'.$j]."#";
			}
			else if($_POST['txtINInput'.$j] != 0 && $_POST['txtINInput'.$j] == $t2)
			{
				//echo 'b'.$_POST['txtINInput'.$j]." == ".$t2."<br>";
				header("location:?ch=status&au=12&msg=0");
				exit;
			}else $data['di_inputPort'] .= "";
		}
	}
	
	/*output Port numbers*/
	if($_POST[txtNoofOutput] > 0)
	{
		$t3 = -1;
		for($j=1;$j<=$_POST[txtNoofOutput];$j++)
		{
			if($_POST['txtOUTInput'.$j] != 0 && $_POST['txtOUTInput'.$j] != $t3)
			{
				$t3 = $_POST['txtOUTInput'.$j];
				$data['di_outputPort'] .= $_POST['txtOUTLabelInput'.$j]."_".$_POST['txtOUTInput'.$j]."#";
			}
			else if($_POST['txtOUTInput'.$j] != 0 && $_POST['txtOUTInput'.$j] == $t3)
			{
				header("location:?ch=status&au=12&msg=0");
				exit;
			}else $data['di_outputPort'] .= "";
		}
	}
	
	if($_POST['txtMobileNo'])
	$data['di_mobileNo'] = $_POST[txtMobileNo];
	
	$data['di_updateDate'] = "NOW()";

	$data['di_userId'] = $_POST[txtClientUserId];
	$data['di_clientId'] = $_POST[txtClientId];

	
	$data['di_mapIcon'] = $_POST[rdDevImg];
	if($_SESSION[superID]!="")
	{
		$data['di_status'] = $_POST[txtStatus];
	}
	
	if($_FILES["fileDeviceLogo"]["name"]!='')
	{
		$type = explode("/",$_FILES["fileDeviceLogo"]["type"]);
		$filename = time().".".$type[1];
		if ((($_FILES["fileDeviceLogo"]["type"] == "image/gif")
		|| ($_FILES["fileDeviceLogo"]["type"] == "image/jpeg")
		|| ($_FILES["fileDeviceLogo"]["type"] == "image/pjpeg"))
		&& ($_FILES["fileDeviceLogo"]["size"] < 200000))
		{
			if ($_FILES["fileDeviceLogo"]["error"] > 0)
			{
				echo "Return Code: " . $_FILES["fileDeviceLogo"]["error"] . "<br />";
				//header("location:?ch=status&au=7&msg=1");
				//exit;
			}
			else
			{
				if (file_exists("unit_img/" . $filename))
				{
					echo $_FILES["fileDeviceLogo"]["name"] . " already exists. ";
					//header("location:?ch=status&au=7&msg=0");
					//exit;
				}
				else
				{
					move_uploaded_file($_FILES["fileDeviceLogo"]["tmp_name"],"unit_img/" . $filename);
					$data['di_deviceImg'] = $filename;
				}
			}
		}
	}
	else
	{
		if($_POST[rdDevImg]!=""){$data['di_deviceImg'] = $_POST[rdDevImg];}
	}
	
echo "<br><br>";
print_r($data);
//exit;

if($db->query_update("tb_deviceinfo", $data , "di_id=".$_POST[txtDeviceId]))
	$res = 1;
else $res = 0;

header("location:?ch=status&au=13&msg=".$res);
exit;

}


?>